﻿@using Stamp_For_Africa_Version_2.Helpers
@using Stamp_For_Africa_Version_2.ViewModels
@model Stamp_For_Africa_Version_2.Models.Stamp
@{
	ViewBag.Title = "Edit Stamp";
}
<h2>Editing stamp: @Model.DisplayName</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.datepicker.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.13.min.js")" type="text/javascript"></script>
<script src="@Url.Content("/uploadify/swfobject.js")" type="text/javascript"></script>
<script src="@Url.Content("/uploadify/jquery.uploadify.v2.1.4.min.js")" type="text/javascript"></script>

<link href="@Url.Content("/uploadify/uploadify.css")" rel="stylesheet" type="text/css" />


<script type="text/javascript">

	$(function () {
		$(".navbutton1").button({

		});
	});


	$(function () {

		// Uploadify File Upload System
		// SessionSync data is sent in scriptData for security reasons, see UploadifySessionSync() in global.asax

		var UploadifyAuthCookie = '@(Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value)';
		var UploadifySessionId = '@Session.SessionID';

		$("#fuFileUploader").uploadify({

			'hideButton': true,       // We use a trick below to overlay a fake html upload button with this hidden flash button                         
			'wmode': 'transparent',
			'uploader': '@Url.Content("/uploadify/uploadify.swf")',
			'cancelImg': '@Url.Content("/uploadify/cancel.png")',
			'buttonText': 'Upload File',
			'script': '@Url.Action("FileUpload", "Stamps")',
			'multi': true,
			'auto': true,
			'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
			'onComplete': function (event, ID, fileObj, response, data) {
				response = $.parseJSON(response);
				if (response.Status == 'OK') {

					$("#UploadedFileName").val(response.returnFile);
					$("#NonRootedUploadedFileName").val(response.serverPath);
					$("#StampImage").attr("src", response.serverPath);
					// Put your own handler code here instead of the following...
					$("#dialogUploadStamp").dialog("close");
				}
			},
			'onError': function (event, queueID, fileObj, errorObj) {
				alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
			}
		});
	});



	$(function () {

		// Uploadify File Upload System
		// SessionSync data is sent in scriptData for security reasons, see UploadifySessionSync() in global.asax

		var UploadifyAuthCookie = '@(Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value)';
		var UploadifySessionId = '@Session.SessionID';

		$("#fileUploaderControlBlock").uploadify({

			'hideButton': true,       // We use a trick below to overlay a fake html upload button with this hidden flash button                         
			'wmode': 'transparent',
			'uploader': '@Url.Content("/uploadify/uploadify.swf")',
			'cancelImg': '@Url.Content("/uploadify/cancel.png")',
			'buttonText': 'Upload File',
			'script': '@Url.Action("FileUpload", "Stamps")',
			'multi': true,
			'auto': true,
			'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
			'onComplete': function (event, ID, fileObj, response, data) {
				response = $.parseJSON(response);
				if (response.Status == 'OK') {

					$("#UploadedControlBlockFileName").val(response.returnFile);
					$("#NonRootedUploadedControlBlockFileName").val(response.serverPath);
					$("#ControlBlockImage").attr("src", response.serverPath);
					// Put your own handler code here instead of the following...
					$("#dialogUploadControlBlock").dialog("close");
				}
			},
			'onError': function (event, queueID, fileObj, errorObj) {
				alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
			}
		});
	});

	function showDialog() {
		$("#dialogUploadStamp").dialog();
		return false;
	}

	function showControlblockDialog() {
		$("#dialogUploadControlBlock").dialog();
		return false;
	}

	$(document).ready(function () {
		$('.date').datepicker({ dateFormat: "dd/mm/yy" });
	});
	
	</script>


@*
  -----------------------------------------------------------------------
  Upload Stamp dialog
  -----------------------------------------------------------------------
*@
<div style="display: none;" id="dialogUploadStamp" title="Upload Stamp">

		<div style="position: relative;">
        
        <input type="button" id="btnUpload" value="Upload File" />

        <div style="position: absolute; top: 4px; left: 3px;">
            <input id="fuFileUploader" name="file_upload" type="file" />
        </div>
    </div>

</div>

@*
  -----------------------------------------------------------------------
  Upload Control block dialog
  -----------------------------------------------------------------------
*@
<div style="display: none;" id="dialogUploadControlBlock" title="Upload control block">
		<div style="position: relative;">
        
        <input type="button" id="btnUploadConrolBlock" value="Upload Control block" />

        <div style="position: absolute; top: 4px; left: 3px;">
            <input id="fileUploaderControlBlock" name="file_upload" type="file" />
        </div>
    </div>
</div>

@*
  -----------------------------------------------------------------------
  Create new country dialog
  -----------------------------------------------------------------------
*@

<script type="text/javascript">

	function showCountryDialog() {
		$("#dialogCreateNewCountry").dialog();
		return false;
	}

	function onCreateCountry() {
		var countryName = $("#CountryName").val();

		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateCountry',
				data: { countryName: countryName },
				dataType: "json",

				success: function (data, response) {

					alert(data.Result);
					var returnCountryName = data.CountryName;
					var returnCountryId = data.CountryId;


					$("#dialogCreateNewCountry").dialog("close");

				}
			});

		return false;
	}
</script>

<div style="display: none;" id="dialogCreateNewCountry" title="Create country">  
		<div style="position: relative;">
        
        @Html.TextBox("CountryName")<br/>   
				<a href="" onclick="return onCreateCountry()">Create country</a>
    </div>    
</div>

@*
	--------------------------------------------------------------------
	Create new artist dialog
	--------------------------------------------------------------------
*@

@* Script *@
<script type="text/javascript">

	function showArtistDialog() {
		$("#dialogCreateNewArtist").dialog({ width: 400 });
		return false;
	}

	function onCreateArtist() {
		var artistName = $("#ArtistName").val();
		var artistSurname = $("#ArtistSurname").val();

		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateArtist',
				data: { name: artistName, surname: artistSurname },
				dataType: "json",

				success: function (data, response) {

					alert(data.Result);
					$("#dialogCreateNewArtist").dialog("close");

				}
			});

		return false;
	}
</script>

@* Dialog *@
<div style="display: none;" id="dialogCreateNewArtist" title="Create artist">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Name:") 
						</td>
						<td>
							@Html.TextBox("ArtistName")<br/>
						</td>
					</tr>
					<tr>
						<td>
							@Html.Label("Surname:") 
						</td>
						<td>
							@Html.TextBox("ArtistSurname")<br/>
						</td>
					</tr>
				</table>
				<a href="" onclick="return onCreateArtist()">Create artist</a>
    </div>    
</div>

@*
	--------------------------------------------------------------------
	Create new currency dialog
	--------------------------------------------------------------------
*@

@* Script *@
<script type="text/javascript">

	function showCurrencyDialog() {
		$("#dialogCreateNewCurrency").dialog({ width: 400 });
		return false;
	}

	function onCreateCurrency() {
		var displayName = $("#CurrenyDisplayName").val();
		var symbol = $("#CurrencySymbol").val();

		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateCurrency',
				data: { displayName: displayName, symbol: symbol },
				dataType: "json",

				success: function (data, response) {

					alert(data.Result);
					$("#dialogCreateNewCurrency").dialog("close");

				}
			});

		return false;
	}
</script>

@* Dialog *@
<div style="display: none;" id="dialogCreateNewCurrency" title="Create currency">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Display name:") 
						</td>
						<td>
							@Html.TextBox("CurrenyDisplayName")<br/>
						</td>
					</tr>
					<tr>
						<td>
							@Html.Label("Symobol:") 
						</td>
						<td>
							@Html.TextBox("CurrencySymbol")<br/>
						</td>
					</tr>
				</table>
				<a href="" onclick="return onCreateCurrency()">Create currency</a>
    </div>    
</div>

@*
	--------------------------------------------------------------------
	Create new Colour dialog
	--------------------------------------------------------------------
*@

@* Script *@
<script type="text/javascript">

	function showColourDialog() {
		$("#dialogCreateNewColour").dialog({ width: 400 });
		return false;
	}

	function onCreateColour() {
		var displayName = $("#ColourDisplayName").val();

		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateColour',
				data: { colourName: displayName },
				dataType: "json",

				success: function (data, response) {

					alert(data.Result);
					$("#dialogCreateNewColour").dialog("close");

				}
			});

		return false;
	}
</script>

@* Dialog *@
<div style="display: none;" id="dialogCreateNewColour" title="Create colour">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Display name:") 
						</td>
						<td>
							@Html.TextBox("ColourDisplayName")<br/>
						</td>
					</tr>
				</table>
				<a href="" onclick="return onCreateColour()">Create colour</a>
    </div>    
</div>

@*
	--------------------------------------------------------------------
	Create new Category dialog
	--------------------------------------------------------------------
*@

@* Script *@
<script type="text/javascript">

	function showCategoryDialog() {
		$("#dialogCreateNewCategory").dialog({ width: 400 });
		return false;
	}

	function onCreateCategory() {
		var name = $("#CategoryName").val();

		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateCategory',
				data: { categoryName: name },
				dataType: "json",

				success: function (data, response) {

					alert(data.Result);
					$("#dialogCreateNewCategory").dialog("close");

				}
			});

		return false;
	}
</script>

@* Dialog *@
<div style="display: none;" id="dialogCreateNewCategory" title="Create colour">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Display name:") 
						</td>
						<td>
							@Html.TextBox("CategoryName")<br/>
						</td>
					</tr>
				</table>
				<a href="" onclick="return onCreateCategory()">Create category</a>
    </div>    
</div>


@* 
	-------------------------------------------------------------------
	Main form
	-------------------------------------------------------------------
*@
@using (Html.BeginForm())
{
	@Html.ValidationSummary(true)
	
	@* Hidden form variables *@
	
	@Html.HiddenFor(model => model.UploadedFileName)
	@Html.HiddenFor(model => model.NonRootedUploadedFileName)
	
	@Html.HiddenFor(model => model.UploadedControlBlockFileName)
	@Html.HiddenFor(model => model.NonRootedUploadedControlBlockFileName)	
	
	
	<fieldset class="roundedpanel">	
		<legend>Images</legend>
		<table>
			<tr>
				<td>
					<div class="navbutton1">									
						<a href="" onclick="return showDialog()">Select the Stamp Image</a>					
					</div>
					<div>
						<img alt ="" src='@Url.Action("ShowStamp", "Stamps", new { Model.Id })' width="100" height=auto/>
					</div>
				</td>
				</tr>
				<tr>
				<td>
					<div class="navbutton1">
					<a href="" onclick="return showControlblockDialog()">Select the Controlblock Image</a>
					</div>
					<div>
						<img id = "ControlBlockImage"  alt ="" src='@Url.Action("ShowControlBlock", "Stamps", new { Model.Id })' width="100" height=auto/>
					</div>
				</td>
			</tr>
		</table>		 
	</fieldset>
	<fieldset class="roundedpanel">
		<legend>Details</legend>

		@* -- Display name -- *@
		<h2>Display name</h2>
		<div class="editor-field">
			@Html.EditorFor(model => model.DisplayName)
			@Html.ValidationMessageFor(model => model.DisplayName)
		</div>

		@* -- Short description -- *@
		<h2>Short description</h2>
		<p>*Please note: this is the short description. Use the "description" edit area below for a full description of the stamp</p>
		<div class="editor-field">
			@Html.EditorFor(model => model.ShortDescription)
		</div>

		@* -- Country -- *@
		<h2>Country</h2>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.CountryId, ListHelpers.Countries)
			<div class="navbutton1">
      <a href="" onclick="return showCountryDialog()">Create a new country</a>
			</div>
			@Html.ValidationMessageFor(model => model.CountryId)
		</div>

		@* -- Face Value -- *@
		<h2>Face Value</h2>
		<div class="editor-field">
			@Html.EditorFor(model => model.FaceValue)
			@Html.ValidationMessageFor(model => model.FaceValue)
		</div>

		@* -- Value: Mint never hinged -- *@
		<h2>Value: Mint Never Hinged</h2>
		<div class="editor-field">
			@Html.EditorFor(model => model.ValueMintNeverHinged)
			@Html.ValidationMessageFor(model => model.ValueMintNeverHinged)
		</div>

		@* -- Value: Mint hinged -- *@
		<h2>Value: Mint Hinged</h2>
		<div class="editor-field">
			@Html.EditorFor(model => model.ValueMintHinged)
			@Html.ValidationMessageFor(model => model.ValueMintHinged)
		</div>

		@* -- Value: Used -- *@
		<h2>Value: Used</h2>
		<div class="editor-field">
			@Html.EditorFor(model => model.ValueUsed)
			@Html.ValidationMessageFor(model => model.ValueUsed)
		</div>

		@* -- Value: Currency --*@
		<h2>Currency</h2>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.CurrencyId, Model.Currencies)
			<div class="navbutton1">
			<a href="" onclick="return showCurrencyDialog()">Create a new currency</a>
			</div>
			@Html.ValidationMessageFor(model => model.CurrencyId)
		</div>


		@* -- Primary colour -- *@		
		<h2>Primary colour</h2>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.PrimaryColorId, Model.Colours)
			<div class="navbutton1">
			<a href="" onclick="return showColourDialog()">Create a new colour</a>
			</div>
			@Html.ValidationMessageFor(model => model.PrimaryColorId)
		</div>

		@* -- Category -- *@
		<h2>Category</h2>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.CategoryId, ListHelpers.Categories)
			<div class="navbutton1">
			<a href="" onclick="return showCategoryDialog()">Create a new category</a>
			</div>
			@Html.ValidationMessageFor(model => model.CategoryId)
		</div>

		@* -- Sub-category -- *@
		<h2>Sub-category</h2>
		<div class="editor-field">
			@Html.EditorFor(model => model.SubCategory)
			@Html.ValidationMessageFor(model => model.SubCategory)
		</div>

		@* -- From Date -- *@
		<h2>From Date (ex: 1981)</h2>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.FromDate,
									new { @class = "date" })

			@Html.ValidationMessageFor(model => model.FromDate)
		</div>

		@* -- To Date -- *@
		<h2>To Date (ex: 1982)</h2>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.ToDate,
									new { @class = "date" })

			@Html.ValidationMessageFor(model => model.ToDate)
		</div>

		@* -- Artist --*@
		<h2>Artist</h2>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.ArtistId, ListHelpers.Artists)
			<div class="navbutton1">
				<a href="" onclick="return showArtistDialog()">Create a new artist</a>
			</div>
			@Html.ValidationMessageFor(model => model.ArtistId)
		</div>

		@* -- Search Tags 1 --*@
		<h2>Search tags</h2>
		<div class="editor-field">
			@Html.EditorFor(model => model.SearchTags1)
			@Html.ValidationMessageFor(model => model.SearchTags1)
		</div>

		@* -- Additional search tags -- *@
		<h2>Additional search tags</h2>
		<div class="editor-field">
			@Html.EditorFor(model => model.SearchTags2)
			@Html.ValidationMessageFor(model => model.SearchTags2)
		</div>

		@* -- Stamp type --*@
		<h2>Stamp Type</h2>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.TypeId, ListHelpers.IssueTypes)
		</div>

    @* -- Watermark --*@
		<h2>Watermark</h2>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.WatermarkId, ListHelpers.Watermarks, "--Select One--")
		</div>


		@* -- Description *@
		<h2>Description</h2>
		<div class="editor-field">
			@Html.TextAreaFor(model => model.Description, new {style="width: 60%; height: 300px"})	
		</div>


		<p>
			<input class="navbutton1" type="submit" value="Update" />
		</p>
	</fieldset>
}

	<div class="navbutton1">
		@Html.ActionLink("Catalogue assignment", "AssignStampToCatalogue", new { stampId = Model.Id })
	</div>
	<div class="navbutton1">
		@Html.ActionLink("Link this stamp to another stamp", "LinkStampToStamp", new { stampId = Model.Id, linkStampViewModel = new LinkStampViewModel() })
	</div>
	<div class="navbutton1">
		@Html.ActionLink("Manage stamp varieties", "ManageStampVariants", new { stampId = Model.Id })
	</div>
	<div class="navbutton1">
		@Html.ActionLink("Back to List", "Index")
	</div>

